-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SIP-399: Perps V3 Flash Loan Utility #2039
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
* @param params Additional parameters for the flash loan operation. | ||
* @return success True if the operation was successful, false otherwise. | ||
*/ | ||
function executeOperation( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please tell me which argument is given to ensure that sandwishes are constrained?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please tell me which argument is given to ensure that sandwishes are constrained?
amountOutMinimum
: https://github.com/Synthetixio/synthetix-v3/blob/b8f01cdaa829f7630c2064ed5717c86d7c3c3dc3/auxiliary/PerpsFlashLoanUtil/contracts/PerpsFlashLoanUtil.sol#L119
which is derived from uniswap's IQuoter.quoteExactInput
:
https://github.com/Uniswap/v3-periphery/blob/main/contracts/interfaces/IQuoter.sol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohhh this amountOutMinimum
is included in calldata
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohhh this
amountOutMinimum
is included incalldata
?
No, we fetch it from the IQuoter at L119 in executeOperation
:
uint256 amountOutMinimum = quoter.quoteExactInput(
abi.encodePacked(collateralType, poolAddress, USDC),
unwrappedAmount
);
And then we use it to do the swap:
ISwapRouter.ExactInputParams memory swapParams = ISwapRouter.ExactInputParams({
path: abi.encodePacked(collateralType, poolAddress, USDC),
recipient: address(this),
deadline: block.timestamp,
amountIn: unwrappedAmount,
amountOutMinimum: amountOutMinimum
});
unwrappedAmount = router.exactInput(swapParams);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe i'm not clear, but how does the front-end is able to specify a minimum amount of USDC that he expects to receive for selling his wETH/wBTC margin so that he doesn't get rugged with a sandwish... Like to protect against this, the front-end gives a user a interface to specify a maximum amount of slippage against a centralized exchange price, that he is willing to accept.. If the return on the uniswap trade yields fewer USDC against the ETH that was to be sold all of it reverts... The uni/flash quoter, which uses on-chain data, I think ensures that the transaction goes through, but does not protect the trader against a sandwish attack which involves pushing uniswap prices around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe i'm not clear, but how does the front-end is able to specify a minimum amount of USDC that he expects to receive for selling his wETH/wBTC margin so that he doesn't get rugged with a sandwish
Ah, I see what you mean. Can we mitigate this by quoting the min amount of USDC in requestFlashLoan
, and pass it to params
for execution? The user can be shown the amount of USDC expected to close their position at the time of requesting.
This way, the user requests a flash loan with a quoted amount in the first block. And then if the price moves down by the following block when the execution is processed, it can compare the initially quoted amount to a new quote and revert if outside the slippage range.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like let's do an example:
- User requests a 1000 usdc flash loan to repay usdc of debt, having 1 ETH margin on hand (3k$)
- Users flash 1000 usdc,
- Swaps ETH to 2000 usdc,
- Repays debt
- Repays flash
At no point in this set of transaction is the rate of swap ETH to USDC is specified. Uness we can configure the maximum amount of ETH margin is allowed to be spent somewhere, or the rate of ETH to USDC,
as per author's request |
This SIP proposes to deploy a new contract,
PerpsFlashLoanUtil
, which will allow users to close their Perps V3 positions by utilizing flash loans.